package com.newcapec.lesson2;

public class Driver extends Person{
    private String cardId;
    private Car car;

    public Driver() {
    }

    public Driver(int age, String name, String sex, String birthday,String cardId, Car car) {
        super( age,  name,  sex,  birthday);
        this.cardId = cardId;
        this.car = car;
    }

    public Driver(Driver driver){
        super(driver);
        this.cardId = driver.cardId;
        //此处有浅拷贝的问题
        //this.car = driver.car;
        //通过拷贝构造改为深拷贝
        this.car = new Car(driver.car);
    }

    public String getCardId() {
        return cardId;
    }

    public void setCardId(String cardId) {
        this.cardId = cardId;
    }

    public Car getCar() {
        return car;
    }

    public void setCar(Car car) {
        this.car = car;
    }

    @Override
    public String toString() {
        return super.toString()+"Driver{" +
                "cardId='" + cardId + '\'' +
                ", car=" + car.toString() +
                '}';
    }
}
